package user_lazy_save_service

import "sen-golang-study/go_game_study/hero_story_go_server/biz_server/service/user/userdata"

func GetUserLazySaver(user *userdata.User) *UserLazySaver {
	if user == nil {
		return nil
	}

	existComponent, _ := user.GetComponentMap().Load("UserLazySaver")

	if existComponent != nil {
		return existComponent.(*UserLazySaver)
	}

	existComponent = &UserLazySaver{
		User: user,
	}

	existComponent, _ = user.GetComponentMap().LoadOrStore("UserLazySaver", existComponent)

	return existComponent.(*UserLazySaver)
}
